<?php if(!defined('IN_WDPHP'))exit('No direct script access.');
/**
 * WDPHP  路由类
 * @package 		WDPHP
 * @author 			肖伟 
 * @version 		v1.0
 * @copyright 		Copyright (c) 2012. widuu.com
 */
 
	class Router{
	/*
	 *URL专为PATHINFO格式
	 */
		static function praseurl(){
			if(isset($_SERVER['PATH_INFO'])){
				//获取pathinfo
				$pathinfo=explode('/',trim($_SERVER['PATH_INFO'],"/"));
				
				//获取action
				$_GET['m']=(!empty($pathinfo[0])?$pathinfo[0]:'index');
				
				//将数组的单元移除数组
				
				
				array_shift($pathinfo);
				
				
				$_GET['a']=(!empty($pathinfo[0])?$pathinfo[0]:'index');
				
				for($i=0; $i<count($pathinfo); $i+=2){
					$_GET[$pathinfo[$i]]=$pathinfo[$i+1];
				}
			}else{
				$_GET["m"]= (!empty($_GET['m']) ? $_GET['m']: 'index');    //默认是index模块
				$_GET["a"]= (!empty($_GET['a']) ? $_GET['a'] : 'index');   //默认是index动作
	
				if($_SERVER["QUERY_STRING"]){
					$m=$_GET["m"];
					unset($_GET["m"]);  //去除数组中的m
					$a=$_GET["a"];
					unset($_GET["a"]);  //去除数组中的a
					$query=http_build_query($_GET);   //形成0=foo&1=bar&2=baz&3=boom&cow=milk格式
					//组成新的URL
					$url=$_SERVER["SCRIPT_NAME"]."/{$m}/{$a}/".str_replace(array("&","="), "/", $query);
					header("Location:".$url);
				}
			}
		}
	}